package com.tuanzi.webtalk.service.impl;

import com.tuanzi.webtalk.dao.FriendMapper;
import com.tuanzi.webtalk.dao.UserMapper;
import com.tuanzi.webtalk.domain.User;
import com.tuanzi.webtalk.service.FriendService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 雄关漫道真如铁，而今迈过从头越
 **/

@Service
public class FriendServiceImpl implements FriendService {

    @Resource
    private FriendMapper friendMapper;

    @Resource
    private UserMapper userMapper;

    @Override
    public List<User> getFriends(Integer id) {

        List<Integer> integers = friendMapper.selectFriends(id);

        List<User> friends = new ArrayList<>();

        for (int i = 0 ; i < integers.size() ; i++){
            User user = userMapper.selectByPrimaryKey(integers.get(i));
            friends.add(user);
        }

        return friends;
    }
}
